package com.ice.body.business.controller;
import com.ice.body.business.model.ReagentMsdsModel;
import com.ice.body.business.model.ReagentStock;
import com.ice.body.business.service.ReagentMsdsService;
import com.ice.body.business.service.ReagentStockService;
import com.ice.body.business.model.ReagentMsdsVo;
import io.swagger.annotations.ApiOperation;
import com.ice.base.controller.BaseController;
import org.apache.poi.ss.formula.functions.T;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2021-11-04
 * Time: 01:08
 */
@RestController
@ApiIgnore(value = "MSDS数据")
public class ReagentMsdsController extends BaseController{
    //---------------------------MSDS数据-----------------------start
    @Resource
    private ReagentMsdsService reagentMsdsService;
    @Resource
    private ReagentStockService reagentStockService;
    @Value("${data.serialNo}")
    private String serialNo;





    @ApiOperation(value = "MSDS数据-新增")
    @PostMapping("/api/ReagentMsds/insert")
    public AjaxResult<ReagentMsdsModel> insert_ReagentMsds(ReagentMsdsModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            model.init(model);
            reagentMsdsService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "MSDS数据-删除")
    @PostMapping("/api/ReagentMsds/deleteById")
    public AjaxResult<ReagentMsdsModel> deleteById_ReagentMsds(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            reagentMsdsService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "MSDS数据-更新")
    @PostMapping("/api/ReagentMsds/updateById")
    public AjaxResult<ReagentMsdsModel> update_ReagentMsds(ReagentMsdsModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            reagentMsdsService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "MSDS数据-查询一个")
    @PostMapping("/api/ReagentMsds/selectById")
    public AjaxResult<ReagentMsdsModel> selectById_ReagentMsds(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           ReagentMsdsModel model = reagentMsdsService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }



    @ApiOperation(value = "MSDS数据-查询分页")
    @PostMapping("/api/ReagentMsds/selectListByPageHelper")
    public AjaxResult<ReagentMsdsModel> selectListByPageHelper_ReagentMsds(@RequestParam(name = "pageSize") Integer pageSize,
                                                                           @RequestParam(name = "pageNum") Integer pageNum,
                                                                           ReagentMsdsModel model){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           list = reagentMsdsService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------MSDS 数据-----------------------end

    @ApiOperation(value = "MSDS数据-生成RFID并打印标签")
    @PostMapping("/api/ReagentMsds/printRFID")
    public AjaxResult<T> printRFID(ReagentStock model) {
        AjaxResult r = ResponseResult.error();
        try{
            model.setSerialNo(serialNo);
            reagentStockService.printRFID(model);
            r = ResponseResult.success();
        }catch (Exception e){
            e.printStackTrace();
        }
        return r;
    }

    //epc菜单点击打印
    @ApiOperation(value = "epc 补打印标签")
    @RequestMapping("/api/ReagentMsds/printEpc")
    @ResponseBody
    public AjaxResult printEpc(String epcCode) {
        try{
            reagentStockService.printEpc(epcCode);
            return AjaxResult.success();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "MSDS数据-查询字典参数")
    @PostMapping("/api_p/msds/selectDict")
    public AjaxResult<ReagentMsdsVo> selectDict() {
        AjaxResult r = ResponseResult.success();
        try{
            List<ReagentMsdsVo> list = reagentMsdsService.selectDict();
            r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }

}
